<template>
	<view class="page_t">
		<pageheader :setting="settingdata"></pageheader>
		<go-top :scrollTop="scrollTop"></go-top>
		<view class="numbers" v-if="type==1">共{{total}}人关注我</view>
		<view class="numbers" v-else>共关注店主{{total}}人</view>
		<view class="contents">
			<view class="searchContent">
				<u-icon name="search" color="#B1B8C8" size="28" class="search_icon" @click="demand"></u-icon>
				<u-input v-model="searchvalue" placeholder="搜索" type="text" :border="false"
					placeholderStyle="color:#999999" class="search_" :clearable="false" @confirm="demand" />
			</view>
			<view class="personbox" v-for="(item,index) in list" :key="index">
				<image :src="item.avatar" mode="aspectFill" @click="goStation(item.id)"></image>
				<view class="person_info">
					<view class="personMain" @click="goStation(item.id)">
						<text class="personName clamp2">{{item.shop_name}}</text>
						<text class="personPhone">{{item.tel}}</text>
					</view>
					<view class="personContacts">
						<view class="">
							<text class="iconfont icon-dilanxianxingiconyihuifu_huabanfuben"
								@click="tochat(item)"></text>
							<text class="iconfont icon-dianhua1" @click="dialing(item.id,item.tel)"></text>
						</view>
						<view class="attention" @click="attention(item)">取消关注</view>
					</view>
				</view>
			</view>
		</view>
		<view class="not_more" v-if="list.length<1">
			<image src="../static/img/wshangji.png" mode="widthFix"></image>
			<view class="text">暂无关注</view>
		</view>
		<view class="nomore" v-if="nomore&&list.length>0">—— · 没有更多了 · ——</view>
	</view>
</template>

<script>
	var _this, $paginator;
	export default {
		data() {
			return {
				settingdata: {
					name: '关注我的',
					bgColor: '#fff',
					titleColor: '#000000',
					showNav: true,
					showTypes: 0,
					position: "metionme"
				},
				list: [],
				nomore: false,
				// 回到头部按钮距离
				scrollTop: 0,
				searchvalue: '',
				type: 1, //1我的粉丝 2我的关注
				// 关注人数
				total: 0,
			}
		},
		onLoad(e) {
			_this = this
			_this.type = e.type
			_this.settingdata.name = e.type == 1 ? "我的粉丝" : "我的关注"
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		//下拉刷新
		onPullDownRefresh() {
			$paginator = new _this.$paginator(_this.$api)
			_this.getdata(true)
		},
		onReachBottom: function() {
			$paginator.nextPager(() => {
				_this.getdata()
			})
		},
		methods: {
			tochat(e) {
				let list = {}
				list = {
					to_id: e.id,
					from_id: wx.getStorageSync('client_uid'),
					name: e.shop_name
				}
				wx.setStorageSync('list', list)
				uni.navigateTo({
					url: '/chat/chatingroom?type=2' + '&member_type=1'
				})
			},
			getdata: function(firstLoad = false) {
				let url = ""
				if (_this.type == 1) {
					url = "getfollowme"
				} else {
					url = "getfollow"
				}
				$paginator.getData(url, {
					search: _this.searchvalue
				}, (data) => {
					if (firstLoad) {
						_this.list = data.list ? data.list : []
					} else {
						_this.list = _this.list.concat(data.list)
					}
					_this.nomore = data.nomore
					_this.total = data.total
				})
			},

			// 查询数据
			demand() {
				$paginator = new _this.$paginator(_this.$api)
				_this.getdata(true)
			},
			//拨号并记录
			dialing(client_uid, mobile) {
				_this.$api.post("calllog", {
					calllog_uid: client_uid,
					call_type: 3
				}).then(data => {
					_this.$plug.dialing(mobile)
				});
			},
			goStation(id) {
				uni.navigateTo({
					url: "/home/station/stationpage?id=" + id
				})
			},

			// 关注
			attention(e) {
				console.log(e)
				_this.$api.islogin(() => {
					_this.$api.get("savefollow", {
						select_type: 1,
						types: 3,
						id: e.id
					}).then(data => {

						$paginator = new _this.$paginator(_this.$api)
						_this.getdata(true)
					});
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page_t {
		min-height: 100vh;
		background-color: #f2f2f2;
		display: flex;
		flex-direction: column;
		align-items: center;

		.numbers {
			height: 68rpx;
			width: 100%;
			text-align: center;
			line-height: 68rpx;
			color: #B4B3B3;
			font-size: 24rpx;
		}

		.contents {
			padding: 36rpx 32rpx 40rpx 30rpx;
			display: flex;
			flex-direction: column;
			background-color: #fff;

			.searchContent {
				width: 688rpx;
				height: 68rpx;
				border-radius: 34rpx;
				background: #F7F7F7;
				display: flex;
				flex-direction: row;
				align-items: center;

				.search_icon {
					margin-left: 24rpx;
				}

				.search_ {
					color: #333333;
					font-size: 28rpx;
					flex: 1;
					margin: 0 14rpx;
				}
			}

			.personbox {
				display: flex;
				flex-direction: row;
				align-items: center;

				image {
					width: 94rpx;
					height: 94rpx;
					border-radius: 50%;
				}

				.person_info {
					margin-left: 30rpx;
					padding: 37rpx 0;
					display: flex;
					flex-direction: row;
					align-items: center;
					justify-content: space-between;
					border-bottom: 2rpx solid #f2f2f2;
					flex: 1;

					.personMain {
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						.personName {
							color: #333333;
							font-size: 32rpx;
						}

						.personPhone {
							margin-top: 17rpx;
							color: #B6B6B6;
							font-size: 26rpx;
						}
					}

					.personContacts {
						display: flex;
						flex-direction: row;
						align-items: center;

						text {
							font-size: 40rpx;
							color: #38BE8C;
							margin: 0 21rpx;
						}

						.attention {
							display: flex;
							align-items: center;
							justify-content: center;
							width: 135rpx;
							border-radius: 40rpx;
							text-align: center;
							border: 1rpx solid #38be8c;
							padding: 6rpx 0;
							font-size: 26rpx;
							color: #38be8c;
						}
					}
				}
			}
		}
	}
</style>
